package com.abvnet.project.water.api.web;

import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.project.system.dept.service.IDeptService;
import com.abvnet.project.water.project.domain.ProjectInfo;
import com.abvnet.project.water.project.service.IProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/project")
public class ApiProjectInfoController extends BaseController {

    @Autowired
    private IProjectInfoService projectInfoService;
    @Autowired
    private IDeptService deptService;

    @GetMapping("/list")
    public AjaxResult list(ProjectInfo projectInfo) {
        startPage();
        List<ProjectInfo> list = projectInfoService.selectListForApi(projectInfo);
        return pageSuccess(list);
    }

    @GetMapping("/get")
    public AjaxResult get(@RequestParam("projectId") Long projectId) {
        return AjaxResult.success(projectInfoService.selectProjectInfoById(projectId));
    }

    @GetMapping("/diagnosis")
    public AjaxResult diagnosis(@RequestParam("projectId") Long projectId) {
        return AjaxResult.success(projectInfoService.selectDiagnosisByProjectId(projectId));
    }

    @PostMapping("/edit")
    public AjaxResult editSave(ProjectInfo projectInfo) {
        return AjaxResult.success(projectInfoService.updateProjectInfoForApi(projectInfo));
    }

    @GetMapping("/summary")
    public AjaxResult summary(@RequestParam("projectId") Long projectId) {
        return AjaxResult.success(projectInfoService.selectSummaryByProjectId(projectId));
    }

    @GetMapping("/map")
    public AjaxResult map() {
        return AjaxResult.success(projectInfoService.selectMapList());
    }

    @GetMapping("/area")
    public AjaxResult area() {
        return AjaxResult.success(projectInfoService.selectAreaList());
    }

    @GetMapping("/industry")
    public AjaxResult industry() {
        return AjaxResult.success(projectInfoService.selectIndustryList());
    }

    @GetMapping("/rate")
    public AjaxResult rate() {
        return AjaxResult.success(projectInfoService.selectRepRateList());
    }

    /**
     * 获得客户数据
     * @return
     */
    @GetMapping("/getCustomer")
    public AjaxResult getCustomer() {
        return AjaxResult.success(deptService.selectChildrenDeptByParentId(Long.parseLong("106")));
    }

    /**
     * 新增项目
     * @param projectInfo 项目实体
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(ProjectInfo projectInfo) {
        return AjaxResult.success(projectInfoService.insertProjectInfoForApp(projectInfo));
    }
}
